package net.suncaper.demo.service;

import net.suncaper.demo.domain.User;
import net.suncaper.demo.domain.UserExample;
import net.suncaper.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> findUser(){
        return userMapper.selectByExample(new UserExample());
    }
    @Override
    public void saveUser(User user){
        SimpleDateFormat ct=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String log_createtime=ct.format(new Date());
        user.setUserCreatetime(log_createtime);
        userMapper.insert(user);
    }

    @Override
    public List<User> selectUserByEmail(String email) {
        List<User>clist=new ArrayList<User>();
        UserExample example=new UserExample();
        example.createCriteria().andUserEmailEqualTo(email);
        clist=userMapper.selectByExample(example);

        return clist;
    }

    @Override
    public void updateUserInfo(User user, int id) {
        List<User>clist=new ArrayList<User>();
        UserExample example=new UserExample();
        example.createCriteria().andUserIdEqualTo(id);
        user.setUserId(id);
        userMapper.updateByExample(user,example);
    }



}
